#include "signup.h"
#include "ui_signup.h"
#include<QPainter>
#include<QPixmap>
#include<QMessageBox>
#include <QGraphicsDropShadowEffect>
#include"qdialoglogin.h"
#include<QMovie>


Signup::Signup(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Signup)
{
    ui->setupUi(this);
    //qt实现动图播放
    QMovie *movie=new QMovie("C:/Qt/PROJECT_LEE/images/1.gif");
 //   QMovie *movie=new QMovie(":/../PROJECT_LEE/images/1.gif");//资源
    ui->label_gif->setMovie(movie);
    movie->start();

    //设置图片
    QPixmap pic;
      QSize size;//画框大小
      pic.load("C:/Qt/PROJECT_LEE/images/sign.png");
      //设置图片显示尺寸
      size.setHeight(ui->label_png->height());
      size.setWidth(ui->label_png->width());
      //照片处理
      pic=pic.scaled(size,Qt::IgnoreAspectRatio);
      //显示
    ui->label_png->setPixmap(pic);

    //设置阴影
    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
    shadow->setOffset(-3, 0);
    shadow->setColor(QColor("#888888"));
    shadow->setBlurRadius(30);
    ui->label_png->setGraphicsEffect(shadow);
    //无边框但在任务栏上显示标题
      this->setWindowFlags(Qt::FramelessWindowHint);

}

Signup::~Signup()
{
    delete ui;
}


//返回登录
void Signup::on_pushButton_return_clicked()
{   this->close();
    QDialogLogin *D=new QDialogLogin;

    D->show();
}

//注册
void Signup::on_pushButton_sure_clicked()
{

    sqlite_Init();
    QString username = ui->lineEdit_username->text();
        QString password = ui->lineEdit_passwd->text();
        QString surepass = ui->lineEdit_surepasswd->text();

        if(password == surepass)
            {
                QString sql=QString("insert into user(username,password) values('%1','%2');")
                        .arg(username).arg(password);
                //创建执行语句对象
                QSqlQuery query;
                //判断执行结果
                if(!query.exec(sql))
                {
                    qDebug()<<"insert into error";
                    QMessageBox::information(this,"注册认证","插入失败！");
                }
                else
                {
                    qDebug()<<"insert into success";
                    QMessageBox::information(this,"注册认证","插入成功！");
                    this->close();
                    QDialogLogin *w = new QDialogLogin;
                    w->show();

                }

            }else{
                QMessageBox::information(this,"注册认证","两次密码输入不一致");
            }
}
//鼠标事件
void Signup::mousePressEvent(QMouseEvent *event)
{
    //event->globalPos()获取鼠标以电脑屏幕左上角为原点的向量
    if(event->button()==Qt::LeftButton)
    {
        this->m_moveing3=true;
        m_lastPos=event->globalPos()-pos();//使用向量的减法获得鼠标相对于窗口的位置

    }
    return  QWidget::mousePressEvent(event);

}

void Signup::mouseMoveEvent(QMouseEvent *event)
{
    //在mouseMoveEvent 里event->button()返回的引进事件的button永远是Qt::NoButton!!
    if(m_moveing3 && (event->buttons()&&Qt::LeftButton))//左键被按下
    {
        move(event->globalPos()-m_lastPos);
       //m_lastPos=event->globalPos()-pos();//使用向量的减法获得鼠标相对于窗口的位置
    }
   return QWidget::mouseMoveEvent(event);
}

void Signup::mouseReleaseEvent(QMouseEvent *event)
{
   Q_UNUSED(event);
   m_moveing3=false;
}


